﻿using System;
using System.Threading;
using System.Threading.Tasks;

namespace FreesenseSubAIS.Common
{
    /// <summary>
    ///     支持测试线程的设备部件
    /// </summary>
    public  class ThreadPart 
    {
        private CancellationTokenSource _cancelTokenSource;

        public ThreadPart()
        {
            ContinueEvent = new ManualResetEvent(true);
            StopEvent = new ManualResetEvent(false);
            _cancelTokenSource = new CancellationTokenSource();
        }

        /// <summary>
        ///     将指派给测试线程任务的 <see cref="P:System.Threading.Tasks.TaskFactory.CancellationToken" />。
        /// </summary>
        public CancellationToken CancelToken
        {
            get { return _cancelTokenSource.Token; }
        }

        /// <summary>
        ///     继续信号量。
        /// </summary>
        public ManualResetEvent ContinueEvent { get; set; }

        /// <summary>
        ///     停止信号量。
        /// </summary>
        public ManualResetEvent StopEvent { get; set; }

        private void Clean()
        {
            //var ini = this as INeedClean;
            //if (ini != null)
            //    ini.Clean();
            _cancelTokenSource = null;
        }
    }
}